#include <iostream>
#include <pthread.h>
#include <string>
#include <vector>
#include<ctime>
#include<unistd.h>
#include "RingQueue.hpp"
void *Consumer(void *args)
{
    RingQueue<int> *bq = static_cast<RingQueue<int> *>(args);
    while (true)
    {
        int out;
        bq->Pop(&out);
        std::cout<<"Consumer get "<< out<<std::endl;
        //sleep(2);
    }
    return nullptr;
}
void *Productor(void *args)
{
    RingQueue<int> *bq = static_cast<RingQueue<int> *>(args);
    while (true)
    {
        //1.造数据
        int in = rand() % 5 + 1;
        //2.插入数据
        bq->Push(in);
        std::cout<<"Productor creat "<< in<<std::endl;
        sleep(2);
        
    }
    return nullptr;
}
int main()
{
    // 创建生产者，消费者
    srand(time(nullptr));
    RingQueue<int> *bq = new RingQueue<int>();
    pthread_t c1, c2, p1, p2;
    pthread_create(&c1, nullptr, Consumer, bq);
    pthread_create(&c2, nullptr, Consumer, bq);
    pthread_create(&p1, nullptr, Productor, bq);
    pthread_create(&p2, nullptr, Productor, bq);

    pthread_join(p1,nullptr);
    pthread_join(p2,nullptr);
    pthread_join(c1,nullptr);
    pthread_join(c2,nullptr);

    return 0;
}